﻿namespace Sai.Core.Reporting
{
    using System.Collections.Generic;

    public class ReportStyleRegistry
    {
        private List<IReportStyleRepository> repositories = new List<IReportStyleRepository>();

        public void Add(IReportStyleRepository repo)
        {
            this.repositories.Add(repo);
        }

        public IReportStyler Find(string styleName)
        {
            IReportStyler styler = null;

            foreach (var repo in this.repositories)
            {
               var candidate = repo.Find(styleName);

                if (candidate != null && candidate.IsValid)
                {
                    styler = candidate;
                    break;
                }
            }

            return styler;
        }
    }
}
